<template>
    <div>
         <h3>登录</h3>
         <table class="table">
                <thead>
                      <tr>  
                        <th>账号</th>
                        <th><input type="text" v-model="logindata.name"></th>
                      </tr>
                      <tr>  
                        <th>密码</th>
                        <th><input type="password" v-model="logindata.pwd"></th>
                      </tr>
                      <tr>  
                        <th colspan="2">
                            <input type="button" value="登录" class="btn btn-success" @click="Login">
                        </th>
                      </tr>
                </thead>
         </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
const router=useRouter()

const logindata=ref({
  name:'',
  pwd:''
})
const  Login=()=>{
  if(logindata.value.name=="")
{
  alert('账号不能为空!!')
    return;
}
if(logindata.value.pwd=="")
{
  alert('密码不能为空!!')
    return;
}
  axios.get('/api/User/Login',{params:logindata.value}).then(res=>{
   if(res.data.userId==-1)
   {
    alert('账号不存在!!')
    return;
   }
   else  if(res.data.userId==-2)
   {
    alert('密码错误!!')
    return;
   }
   else  if(res.data.userId>0)
   {
    alert('登录成功!!')
    router.push('/showall')
    
   }
  })
}
</script>

<style scoped>

</style>